package com.assist.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.primefaces.event.RowEditEvent;

import com.assist.model.Activity;
import com.assist.service.IActivityService;
import com.assist.service.impl.ActivityServiceImpl;
import com.assist.service.impl.CategoryServiceImpl;

@ManagedBean(name = "activityTableBean")
@SessionScoped
public class ActivityTableBean implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
    private List<Activity> activities;
    
    private IActivityService activityService;
    
    
	public ActivityTableBean() {
		
		activityService = new ActivityServiceImpl();	
		populateActivies();
	}

	private List<Activity> populateActivies() {
		
		FacesContext context = FacesContext.getCurrentInstance(); 
		HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();  
		HttpSession httpSession = request.getSession(false);  
		String loginUserName= (String) httpSession.getAttribute("loginUserName");
		
	
		activities = activityService.getActivitiesByUserName(loginUserName);
		return activities;

	}

	public List<Activity> getActivities() {
		
		return populateActivies();
	}


    public void onEdit(RowEditEvent event) {
        FacesMessage msg = new FacesMessage("Activity Edited", ((Activity) event.getObject()).getId().toString());

        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    
    public void onCancel(RowEditEvent event) {
        FacesMessage msg = new FacesMessage("Car Cancelled", ((Activity) event.getObject()).getId().toString());

        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
	

}
